package org.mokusakura.service.impl;

import org.mokusakura.domain.History;
import org.mokusakura.domain.User;
import org.mokusakura.persistence.mapper.HistoryMapper;
import org.mokusakura.service.HistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;

/**
 * @author MokuSakura
 */
@Service
public class HistoryServiceImpl implements HistoryService {
    @Autowired
    private HistoryMapper historyMapper;


    @Override
    public History addHistory(User user, String category, Timestamp timestamp) {
        History history = null;
        if (historyMapper.insertUserHistory(user.getId(), category, timestamp) == 1) {
            history = new History();
            history.setUserId(user.getId());
            history.setId(category);
            history.setTimestamp(timestamp);
        }
        return history;
    }

    @Override
    public History addItemHistory(User user, String itemID, Timestamp timestamp) {
        History history = null;
        if (historyMapper.insertUserItemHistory(user.getId(), itemID, timestamp) == 1) {
            history = new History();
            history.setUserId(user.getId());
            history.setId(itemID);
            history.setTimestamp(timestamp);
        }
        return history;
    }

    @Override
    public History addProductHistory(User user, String productID, Timestamp timestamp) {
        History history = null;
        if (historyMapper.insertUserProductHistory(user.getId(), productID, timestamp) == 1) {
            history = new History();
            history.setUserId(user.getId());
            history.setId(productID);
            history.setTimestamp(timestamp);
        }
        return history;
    }
}
